#include "stdafx.h"
#include "ccube.h"

CCube::CCube()
{
	cord_x = cord_y = cord_z = 0;
	angle = x = y = z = 0;
	scale_x = scale_y = scale_z = 0;
	r = g = b = 0;
}
CCube::~CCube()
{
}
void CCube::draw(bool stripes, bool alpha)
{
	//iluminacion
	//GLfloat material[] = {255.0,1.0,1.0,1.0};
	//glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,(GLfloat *)material);
	
	glEnable(GL_TEXTURE_2D);

	//dibujar triangulos
	glBindTexture(GL_TEXTURE_2D,m_idTexture);

	if(stripes)
	{
		glBegin(GL_LINE_STRIP);
		//printf("lineas\n");
	}
	else
	{
		glBegin(GL_TRIANGLES);
		//printf("triangulos\n");
	}
	if(true)
	{
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	}


	//cara 1
	//1er tringulo
	glNormal3f(0, 0, 1);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0, 0, 1);
	glTexCoord2f(1.0,1.0);
	glVertex3f(1, 0, 1);
	glTexCoord2f(0.0,0.0);
	glVertex3f(0, 1, 1);
	//2do triangulo
	glNormal3f(0, 0, 1);
	glTexCoord2f(1.0,1.0);
	glVertex3f(1, 0, 1);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1, 1, 1);
	glTexCoord2f(0.0,0.0);
	glVertex3f(0, 1, 1);
	//cara 2
	//2do triangulo
	glNormal3f(1, 0, 0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(1, 0, 1);
	glTexCoord2f(1.0,1.0);
	glVertex3f(1, 0, 0);
	glTexCoord2f(0.0,0.0);
	glVertex3f(1, 1, 1);
	//2do triangulo
	glNormal3f(1, 0, 0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(1, 0, 0);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1, 1, 0);
	glTexCoord2f(0.0,0.0);
	glVertex3f(1, 1, 1);
	//cara 3
	//2do triangulo
	glNormal3f(0, 0, -1);
	glTexCoord2f(0.0,1.0);
	glVertex3f(1, 0, 0);
	glTexCoord2f(1.0,0.0);
	glVertex3f(0, 1, 0);
	glTexCoord2f(0.0,0.0);
	glVertex3f(1, 1, 0);
	//2do triangulo
	glNormal3f(0, 0, -1);
	glTexCoord2f(1.0,0.0);
	glVertex3f(0, 1, 0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(1, 0, 0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(0, 0, 0);
	//cara 4
	//2do triangulo
	glNormal3f(-1, 0, 0);
	glTexCoord2f(1.0,0.0);
	glVertex3f(0, 1, 1);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0, 0, 0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(0, 0, 1);
	//2do triangulo
	glNormal3f(-1, 0, 0);
	glTexCoord2f(1.0,0.0);
	glVertex3f(0, 1, 1);
	glTexCoord2f(0.0,0.0);
	glVertex3f(0, 1, 0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0, 0, 0);
	//cara 5
	//2do triangulo
	glNormal3f(0, -1, 0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0, 0, 1);
	glTexCoord2f(1.0,1.0);
	glVertex3f(0, 0, 0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(1, 0, 0);
	//2do triangulo
	glNormal3f(0, -1, 0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0, 0, 1);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1, 0, 0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(1, 0, 1);
	//cara 6
	//2do triangulo
	glNormal3f(0, 1, 0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0, 1, 0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(0, 1, 1);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1, 1, 1);
	//2do triangulo
	glNormal3f(0, 1, 0);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1, 1, 1);
	glTexCoord2f(0.0,0.0);
	glVertex3f(1, 1, 0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0, 1, 0);
	glEnd();
	//END dibujar triangulos

	if(true)
	{
		glDisable(GL_BLEND);
	}
	
}
void CCube::setPosition(float cord_x, float cord_y, float cord_z)
{
	glTranslatef(cord_x, cord_y, cord_z);	
}
void CCube::setColor(float r, float g, float b)
{
	GLfloat mat_specular[] = {r ,g ,b, 0.5};
	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_specular);
}
void CCube::setRotation(float angle, float x, float y, float z)
{
	glRotatef(angle, x, y, z);
}
void CCube::setScale(float x, float y, float z)
{
	glScalef(x, y ,z);
}
void CCube::setTexture(char *pFilename)
{
	m_idTexture = SOIL_load_OGL_texture(pFilename,0,0,0);
}